package com.company.project.web;

import com.company.project.core.LayUiTableJson;
import com.company.project.core.Page;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Description:
 *
 * @author:
 * Date: 2020-04-02
 * Time: 15:49
 */
@RestController
@RequestMapping("student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping("/page/manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/student/studentList.html");
        return modelAndView;
    }

    @GetMapping("/page/detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/student/studentAdd.html");
        return modelAndView;
    }


    @PostMapping("/upload")
    public Result upload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return ResultGenerator.genFailResult();
        }
        return studentService.upload(file);
    }

    @RequestMapping("queryStudentPage")
    public LayUiTableJson queryStudentPage(String studentName, String college, String professional,
                                           Integer status, @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        Result Result = studentService.queryStudentPage(studentName,college,professional
                ,status,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)Result.getData());
        return layUiTableJson;
    }

    @RequestMapping("getStaticByAge")
    public Result getStaticByAge(){
        return studentService.getStaticByAge();
    }

    @RequestMapping("getStaticByProvince")
    public Result getStaticByProvince(){
        return studentService.getStaticByProvince();
    }

    @RequestMapping("getStaticByGender")
    public Result getStaticByGender(){
        return studentService.getStaticByGender();
    }

    @RequestMapping("getStaticByNation")
    public Result getStaticByNation(){
        return studentService.getStaticByNation();
    }

}
